package com.taldh.jvm.gc;

public class RSetTest {

    static Object[] largeObjects =new Object[1024 * 1024];
    static Object[] largeObjects2 = new Object[1024 * 1024];
    static int[] temp;

    /**
     * -Xmx256m -XX:+UseG1GC -XX:G1ConcRefinementThreads=4 -XX:G1ConcRefinementGreenZone=1
     * -XX:G1ConcRefinementYellowZone=2 -XX:G1ConcRefinementRedZone=3
     * -XX:+UnlockExperimentalVMOptions -XX:G1LogLevel=finest
     * -XX:+UnlockDiagnosticVMOptions -XX:+G1TraceConcRefinement -XX:+PrintGCTimeStamps
     * -XX:+G1SummarizeRSetStats
     */

    public static void main(String[] args) {
        int numGCs = 200;

        for (int i = 0; i < numGCs - 1; i++) {
            for (int j = 0; j < largeObjects.length; j++) {
                largeObjects[i] = largeObjects2;
            }

            for (int j = 0; j < largeObjects2.length; j++) {
                largeObjects2[i] = largeObjects;
            }

            for (int j = 0; j < 1024; j++) {
                temp = new int[1024];
            }

            System.gc();
        }

    }

    //```
    //Before GC RS summary 
    //
    // Recent concurrent refinement statistics
    //  Processed 0 cards
    //  Of 0 completed buffers:
    //            0 (  0.0%) by concurrent RS threads.
    //            0 (  0.0%) by mutator threads.
    //  Did 0 coarsenings.
    //  Concurrent RS threads times (s)
    //          0.00     0.00     0.00     0.00     0.00     0.00
    //  Concurrent sampling threads times (s)
    //          0.00
    //
    // Current rem set statistics
    //  Total per region rem sets sizes = 92K. Max = 3736B.
    //          55K ( 60.3%) by 19 Young regions
    //           0B (  0.0%) by 0 Humonguous regions
    //          36K ( 39.7%) by 13 Free regions
    //           0B (  0.0%) by 0 Old regions
    //   Static structures = 1736B, free_lists = 0B.
    //    0 occupied cards represented.
    //            0 (  0.0%) entries by 19 Young regions
    //            0 (  0.0%) entries by 0 Humonguous regions
    //            0 (  0.0%) entries by 13 Free regions
    //            0 (  0.0%) entries by 0 Old regions
    //    Region with largest rem set = 31:(E)[0x00000000fff00000,0x0000000100000000,0x0000000100000000], size = 3736B, occupied = 0B.
    //  Total heap region code root sets sizes = 2648B.  Max = 856B.
    //        2440B ( 92.1%) by 19 Young regions
    //           0B (  0.0%) by 0 Humonguous regions
    //         208B (  7.9%) by 13 Free regions
    //           0B (  0.0%) by 0 Old regions
    //    37 code roots represented.
    //           37 (100.0%) elements by 19 Young regions
    //            0 (  0.0%) elements by 0 Humonguous regions
    //            0 (  0.0%) elements by 13 Free regions
    //            0 (  0.0%) elements by 0 Old regions
    //    Region with largest amount of code roots = 31:(E)[0x00000000fff00000,0x0000000100000000,0x0000000100000000], size = 856B, num_elems = 22.
    //After GC RS summary
    //
    // Recent concurrent refinement statistics
    //  Processed 0 cards
    //  Of 0 completed buffers:
    //            0 (  0.0%) by concurrent RS threads.
    //            0 (  0.0%) by mutator threads.
    //  Did 0 coarsenings.
    //  Concurrent RS threads times (s)
    //          0.00     0.00     0.00     0.00     0.00     0.00
    //  Concurrent sampling threads times (s)
    //          0.00
    //
    // Current rem set statistics
    //  Total per region rem sets sizes = 95K. Max = 7792B.
    //          13K ( 13.9%) by 3 Young regions
    //           0B (  0.0%) by 0 Humonguous regions
    //          67K ( 71.2%) by 24 Free regions
    //          14K ( 14.8%) by 5 Old regions
    //   Static structures = 1736B, free_lists = 0B.
    //    0 occupied cards represented.
    //            0 (  0.0%) entries by 3 Young regions
    //            0 (  0.0%) entries by 0 Humonguous regions
    //            0 (  0.0%) entries by 24 Free regions
    //            0 (  0.0%) entries by 5 Old regions
    //    Region with largest rem set = 12:(S)[0x00000000fec00000,0x00000000fed00000,0x00000000fed00000], size = 7792B, occupied = 0B.
    //  Total heap region code root sets sizes = 5408B.  Max = 4912B.
    //        4944B ( 91.4%) by 3 Young regions
    //           0B (  0.0%) by 0 Humonguous regions
    //         384B (  7.1%) by 24 Free regions
    //          80B (  1.5%) by 5 Old regions
    //    31 code roots represented.
    //           31 (100.0%) elements by 3 Young regions
    //            0 (  0.0%) elements by 0 Humonguous regions
    //            0 (  0.0%) elements by 24 Free regions
    //            0 (  0.0%) elements by 5 Old regions
    //    Region with largest amount of code roots = 12:(S)[0x00000000fec00000,0x00000000fed00000,0x00000000fed00000], size = 4912B, num_elems = 31.
    //```
}
